package it.unibo.android.convoycruisecontrol.chiefboatsubsystem;

import java.io.File;

import com.google.android.maps.MapActivity;

import it.unibo.contact.boatSubSystem.BoatSubSystemLauncher;
import it.unibo.contact.chiefBoatSubSystem.ChiefBoatSubSystemLauncher;
import it.unibo.convoycruisecontrol.chiefboatsubsystem.ControlPanel;
import it.unibo.convoycruisecontrol.chiefboatsubsystem.IFlagDisplay;
import it.unibo.convoycruisecontrol.progettodesignandroid.R;
import it.unibo.convoycruisecontrol.progettodesignandroid.R.id;
import it.unibo.convoycruisecontrol.progettodesignandroid.R.layout;
import it.unibo.convoycruisecontrol.progettodesignandroid.R.menu;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

public class ChiefActivity extends MapActivity {

	ChiefBoatSubSystemLauncher launcher;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        AlertDialog alertDialog = new AlertDialog.Builder(ChiefActivity.this).create();
		alertDialog.setTitle("Boat Number");
		LayoutInflater inflater = this.getLayoutInflater();
		final View dialogView = inflater.inflate(R.layout.dialog_layout, null);
		alertDialog.setView(dialogView);
		alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {

				EditText boatNumberEditText = (EditText)dialogView.findViewById(R.id.boatNumber);
				int number = Integer.parseInt(boatNumberEditText.getText().toString());
				launch(number);
			}
		});
		alertDialog.show();
		
    }
    
    protected void launch(int boatNumber)
	{
		launcher = new AndroidChiefBoatSubSystemLauncher(this);
		launcher.initConvoyInformations(new File("/data/convoy/convoy-android.xml"), boatNumber);
		launcher.doJob();
	}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_chief, menu);
        return true;
    }

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
}
